<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>nBot: lcd.c Quellcode</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Erzeugt von Doxygen 1.5.2 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Hauptseite</span></a></li>
    <li><a href="annotated.html"><span>Datenstrukturen</span></a></li>
    <li class="current"><a href="files.html"><span>Dateien</span></a></li>
    <li><a href="dirs.html"><span>Verzeichnisse</span></a></li>
  </ul>
</div>
<div class="tabs">
  <ul>
    <li><a href="files.html"><span>Auflistung&nbsp;der&nbsp;Dateien</span></a></li>
    <li><a href="globals.html"><span>Datei-Elemente</span></a></li>
  </ul>
</div>
<div class="nav">
<a class="el" href="dir_bddd7dc27b566f4752845b32911ef2d1.html">nbot_lib</a></div>
<h1>lcd.c</h1><a href="lcd_8c.html">gehe zur Dokumentation dieser Datei</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/****************************************************************************/</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;avr/io.h&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;avr/pgmspace.h&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include "<a class="code" href="lcd_8h.html" title="Definitionen der Pinbelegung des Displays .">lcd.h</a>"</span>
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="lcd_8c.html#58cb5e934d2dcc17cde426d70ce5d5a0">00047</a> <span class="preprocessor">#define PINOFPORT(x) (*(&amp;x - 2))</span>
<a name="l00048"></a><a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">00048</a> <span class="preprocessor"></span><span class="preprocessor">#define DDROFPORT(x) (*(&amp;x - 1))</span>
<a name="l00049"></a>00049 <span class="preprocessor"></span>
<a name="l00050"></a><a class="code" href="lcd_8c.html#b35032ab368a8bc90798e0c547fb24c2">00050</a> <span class="preprocessor">#define LCD_FUNCTION_4BIT_2LINES 0x28   </span>
<a name="l00051"></a><a class="code" href="lcd_8c.html#c8dd1658e235f174d1cabae5c438943d">00051</a> <span class="preprocessor">#define LCD_BUSY              7         </span>
<a name="l00053"></a><a class="code" href="lcd_8c.html#bd01e64562ef0e704b5402884a269901">00053</a> <span class="preprocessor">#define lcd_e_delay()   __asm__ __volatile__( "rjmp 1f\n 1:" )</span>
<a name="l00054"></a><a class="code" href="lcd_8c.html#d0ce3cd9b481370ad4de36eff08440c8">00054</a> <span class="preprocessor"></span><span class="preprocessor">#define lcd_rw_high()   LCD_CTRL_PORT |= (1&lt;&lt;LCD_PIN_RW)</span>
<a name="l00055"></a><a class="code" href="lcd_8c.html#7f5ebe0ca71b1298a7d3423850cc82b1">00055</a> <span class="preprocessor"></span><span class="preprocessor">#define lcd_rw_low()    LCD_CTRL_PORT &amp;= ~(1&lt;&lt;LCD_PIN_RW)</span>
<a name="l00056"></a><a class="code" href="lcd_8c.html#795b48274d3f80bc744a707b67fd93e9">00056</a> <span class="preprocessor"></span><span class="preprocessor">#define lcd_rs_high()   LCD_CTRL_PORT |= (1&lt;&lt;LCD_PIN_RS)</span>
<a name="l00057"></a><a class="code" href="lcd_8c.html#6edb13d59460246fb4cc32ada1c9f4a8">00057</a> <span class="preprocessor"></span><span class="preprocessor">#define lcd_rs_low()    LCD_CTRL_PORT &amp;= ~(1&lt;&lt;LCD_PIN_RS)</span>
<a name="l00058"></a><a class="code" href="lcd_8c.html#36e38738cd00287b6fb42ff683029aad">00058</a> <span class="preprocessor"></span><span class="preprocessor">#define lcd_e_high()    LCD_CTRL_PORT |= (1&lt;&lt;active_e)</span>
<a name="l00059"></a><a class="code" href="lcd_8c.html#5ca48e29e8aab0646fc0e23c59f6485d">00059</a> <span class="preprocessor"></span><span class="preprocessor">#define lcd_e_low()     LCD_CTRL_PORT &amp;= ~(1&lt;&lt;active_e)</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span>
<a name="l00061"></a><a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">00061</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>;
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 
<a name="l00064"></a>00064 
<a name="l00065"></a>00065 <span class="comment">/*************************************************************************</span>
<a name="l00066"></a>00066 <span class="comment"> delay loop for small accurate delays: 16-bit counter, 4 cycles/loop</span>
<a name="l00067"></a>00067 <span class="comment">*************************************************************************/</span>
<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> _delayFourCycles(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> __count)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070     <span class="keywordflow">if</span> ( __count == 0 )    
<a name="l00071"></a>00071         __asm__ __volatile__( <span class="stringliteral">"rjmp 1f\n 1:"</span> );    <span class="comment">// 2 cycles</span>
<a name="l00072"></a>00072     <span class="keywordflow">else</span>
<a name="l00073"></a>00073         __asm__ __volatile__ (
<a name="l00074"></a>00074             <span class="stringliteral">"1: sbiw %0,1"</span> <span class="stringliteral">"\n\t"</span>                  
<a name="l00075"></a>00075             <span class="stringliteral">"brne 1b"</span>                              <span class="comment">// 4 cycles/loop</span>
<a name="l00076"></a>00076             : <span class="stringliteral">"=w"</span> (__count)
<a name="l00077"></a>00077             : <span class="stringliteral">"0"</span> (__count)
<a name="l00078"></a>00078            );
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 
<a name="l00081"></a>00081 
<a name="l00082"></a>00082 <span class="comment">/************************************************************************* </span>
<a name="l00083"></a>00083 <span class="comment">delay for a minimum of &lt;us&gt; microseconds</span>
<a name="l00084"></a>00084 <span class="comment">the number of loops is calculated at compile-time from MCU clock frequency</span>
<a name="l00085"></a>00085 <span class="comment">*************************************************************************/</span>
<a name="l00086"></a><a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">00086</a> <span class="preprocessor">#define delay(us)  _delayFourCycles( ( ( 1*(F_CPU/4000) )*us)/1000 )</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span>
<a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keywordtype">void</span> toggle_e(<span class="keywordtype">void</span>)
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090     <a class="code" href="lcd_8c.html#36e38738cd00287b6fb42ff683029aad">lcd_e_high</a>();
<a name="l00091"></a>00091     <a class="code" href="lcd_8c.html#bd01e64562ef0e704b5402884a269901">lcd_e_delay</a>();
<a name="l00092"></a>00092     <a class="code" href="lcd_8c.html#5ca48e29e8aab0646fc0e23c59f6485d">lcd_e_low</a>();
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 <span class="keyword">static</span> <span class="keywordtype">void</span> lcd_write(uint8_t data,uint8_t rs) 
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097         <span class="keywordflow">if</span> (rs)
<a name="l00098"></a>00098         {   <span class="comment">/* write data        (RS=1, RW=0) */</span>
<a name="l00099"></a>00099                 <a class="code" href="lcd_8c.html#795b48274d3f80bc744a707b67fd93e9">lcd_rs_high</a>();
<a name="l00100"></a>00100         }
<a name="l00101"></a>00101         <span class="keywordflow">else</span>
<a name="l00102"></a>00102         {    <span class="comment">/* write instruction (RS=0, RW=0) */</span>
<a name="l00103"></a>00103                 <a class="code" href="lcd_8c.html#6edb13d59460246fb4cc32ada1c9f4a8">lcd_rs_low</a>();
<a name="l00104"></a>00104         }
<a name="l00105"></a>00105   
<a name="l00106"></a>00106         <a class="code" href="lcd_8c.html#7f5ebe0ca71b1298a7d3423850cc82b1">lcd_rw_low</a>();
<a name="l00107"></a>00107 
<a name="l00108"></a>00108     
<a name="l00109"></a>00109         <span class="comment">/* configure data pins as output */</span>
<a name="l00110"></a>00110         <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>) |= 0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>;
<a name="l00111"></a>00111 
<a name="l00112"></a>00112         <span class="comment">/* output high nibble first */</span>
<a name="l00113"></a>00113         <a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> = (<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> &amp; (~(0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>))) | ((data &amp; 0xF0) &gt;&gt; (4-<a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>));
<a name="l00114"></a>00114         toggle_e();
<a name="l00115"></a>00115 
<a name="l00116"></a>00116         <span class="comment">/* output low nibble */</span>
<a name="l00117"></a>00117         <a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> = (<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> &amp; (~(0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>))) | ((data &amp; 0x0F) &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>);
<a name="l00118"></a>00118         toggle_e();
<a name="l00119"></a>00119   
<a name="l00120"></a>00120         <span class="comment">/* all data pins high (inactive) */</span>
<a name="l00121"></a>00121         <a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> = (<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> &amp; (~(0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>))) | (0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>);
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00124"></a>00124 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> lcd_read(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> rs) 
<a name="l00125"></a>00125 {
<a name="l00126"></a>00126     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data;
<a name="l00127"></a>00127     
<a name="l00128"></a>00128     <span class="keywordflow">if</span> (rs)
<a name="l00129"></a>00129       <a class="code" href="lcd_8c.html#795b48274d3f80bc744a707b67fd93e9">lcd_rs_high</a>();                       <span class="comment">/* RS=1: read data      */</span>
<a name="l00130"></a>00130                 <span class="keywordflow">else</span>
<a name="l00131"></a>00131       <a class="code" href="lcd_8c.html#6edb13d59460246fb4cc32ada1c9f4a8">lcd_rs_low</a>();                        <span class="comment">/* RS=0: read busy flag */</span>
<a name="l00132"></a>00132     
<a name="l00133"></a>00133     <a class="code" href="lcd_8c.html#d0ce3cd9b481370ad4de36eff08440c8">lcd_rw_high</a>();                           <span class="comment">/* RW=1  read mode      */</span>
<a name="l00134"></a>00134     
<a name="l00135"></a>00135     <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>)=<a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>) &amp; (~(0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>)); <span class="comment">/* configure data pins as input */</span>
<a name="l00136"></a>00136         
<a name="l00137"></a>00137     <a class="code" href="lcd_8c.html#36e38738cd00287b6fb42ff683029aad">lcd_e_high</a>();
<a name="l00138"></a>00138     <a class="code" href="lcd_8c.html#bd01e64562ef0e704b5402884a269901">lcd_e_delay</a>();        
<a name="l00139"></a>00139     data = (<a class="code" href="lcd_8c.html#58cb5e934d2dcc17cde426d70ce5d5a0">PINOFPORT</a>(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>) &lt;&lt; (4-<a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>)) &amp; 0xF0;     <span class="comment">/* read high nibble first */</span>
<a name="l00140"></a>00140     <a class="code" href="lcd_8c.html#5ca48e29e8aab0646fc0e23c59f6485d">lcd_e_low</a>();
<a name="l00141"></a>00141        
<a name="l00142"></a>00142     <a class="code" href="lcd_8c.html#bd01e64562ef0e704b5402884a269901">lcd_e_delay</a>();                       <span class="comment">/* Enable 500ns low       */</span>
<a name="l00143"></a>00143         
<a name="l00144"></a>00144     <a class="code" href="lcd_8c.html#36e38738cd00287b6fb42ff683029aad">lcd_e_high</a>();
<a name="l00145"></a>00145     <a class="code" href="lcd_8c.html#bd01e64562ef0e704b5402884a269901">lcd_e_delay</a>();
<a name="l00146"></a>00146     data |= (<a class="code" href="lcd_8c.html#58cb5e934d2dcc17cde426d70ce5d5a0">PINOFPORT</a>(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>) &gt;&gt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>) &amp; 0x0F;    <span class="comment">/* read low nibble        */</span>
<a name="l00147"></a>00147     <a class="code" href="lcd_8c.html#5ca48e29e8aab0646fc0e23c59f6485d">lcd_e_low</a>();
<a name="l00148"></a>00148     
<a name="l00149"></a>00149     <span class="keywordflow">return</span> data;
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> lcd_waitbusy(<span class="keywordtype">void</span>)
<a name="l00153"></a>00153 {
<a name="l00154"></a>00154     <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c;
<a name="l00155"></a>00155     
<a name="l00156"></a>00156     <span class="comment">/* wait until busy flag is cleared */</span>
<a name="l00157"></a>00157     <span class="keywordflow">while</span> ( (c=lcd_read(0)) &amp; (1&lt;&lt;<a class="code" href="lcd_8c.html#c8dd1658e235f174d1cabae5c438943d">LCD_BUSY</a>)) {}
<a name="l00158"></a>00158     
<a name="l00159"></a>00159     <span class="comment">/* the address counter is updated 4us after the busy flag is cleared */</span>
<a name="l00160"></a>00160     <a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">delay</a>(2);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     <span class="comment">/* now read the address counter */</span>
<a name="l00163"></a>00163     <span class="keywordflow">return</span> (lcd_read(0));  <span class="comment">// return address counter</span>
<a name="l00164"></a>00164 }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> lcd_newline(uint8_t pos)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168     <span class="keyword">register</span> uint8_t addressCounter;
<a name="l00169"></a>00169         
<a name="l00170"></a>00170         <span class="keywordflow">if</span> (pos &lt; 27)
<a name="l00171"></a>00171         addressCounter = 64;
<a name="l00172"></a>00172     <span class="keywordflow">else</span>
<a name="l00173"></a>00173         {
<a name="l00174"></a>00174                 addressCounter = 0;
<a name="l00175"></a>00175                 <span class="keywordflow">if</span> (<a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a> == <a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>)
<a name="l00176"></a>00176                         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#e0219bbb995729c477feeab487f561b5">LCD_PIN_E2</a>;
<a name="l00177"></a>00177                 <span class="keywordflow">else</span>
<a name="l00178"></a>00178                         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>;
<a name="l00179"></a>00179         }
<a name="l00180"></a>00180     <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#fd34054a824de29fcbd441ee67faaf14">LCD_SET_DDRAM</a> + addressCounter);
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183 
<a name="l00184"></a><a class="code" href="lcd_8h.html#7570f3657d5468148afe4f2e356bc41a">00184</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> cmd)
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186     lcd_waitbusy();
<a name="l00187"></a>00187     lcd_write(cmd, 0);
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189 
<a name="l00190"></a>00190 
<a name="l00191"></a><a class="code" href="lcd_8c.html#dbf47a5efdf02367ded1ebf8f9edb5fe">00191</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#dbf47a5efdf02367ded1ebf8f9edb5fe">lcd_gotoxy</a>(uint8_t x, uint8_t y)
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193         <span class="keywordflow">if</span> (y &gt; 1)
<a name="l00194"></a>00194         {
<a name="l00195"></a>00195                 <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>;
<a name="l00196"></a>00196                 y-=2;
<a name="l00197"></a>00197         }
<a name="l00198"></a>00198         <span class="keywordflow">else</span>
<a name="l00199"></a>00199                 <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#e0219bbb995729c477feeab487f561b5">LCD_PIN_E2</a>;
<a name="l00200"></a>00200                 
<a name="l00201"></a>00201         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#fd34054a824de29fcbd441ee67faaf14">LCD_SET_DDRAM</a> + x + (y * 64));      
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 
<a name="l00205"></a><a class="code" href="lcd_8h.html#fa7e36b95c43d603f510273ad077cbbe">00205</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#fa7e36b95c43d603f510273ad077cbbe">lcd_putc</a>(<span class="keywordtype">char</span> c)
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207     uint8_t pos;
<a name="l00208"></a>00208 
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     pos = lcd_waitbusy();   <span class="comment">// read busy-flag and address counter</span>
<a name="l00211"></a>00211     <span class="keywordflow">if</span> (c==<span class="charliteral">'\n'</span>)
<a name="l00212"></a>00212     {
<a name="l00213"></a>00213         lcd_newline(pos);
<a name="l00214"></a>00214     }
<a name="l00215"></a>00215     <span class="keywordflow">else</span>
<a name="l00216"></a>00216     {
<a name="l00217"></a>00217 <span class="preprocessor">#if LCD_WORD_WRAP==1</span>
<a name="l00218"></a>00218 <span class="preprocessor"></span>                <span class="keywordflow">if</span> (pos == 27)
<a name="l00219"></a>00219                 {
<a name="l00220"></a>00220                         lcd_write(<a class="code" href="lcd_8h.html#fd34054a824de29fcbd441ee67faaf14">LCD_SET_DDRAM</a> + 64, 0);
<a name="l00221"></a>00221                 }
<a name="l00222"></a>00222                 <span class="keywordflow">else</span>
<a name="l00223"></a>00223                 {
<a name="l00224"></a>00224                         <span class="keywordflow">if</span> (pos == (64 + 27))
<a name="l00225"></a>00225                         {
<a name="l00226"></a>00226                                 <span class="keywordflow">if</span> (<a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a> == <a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>)
<a name="l00227"></a>00227                                 {
<a name="l00228"></a>00228                                         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#e0219bbb995729c477feeab487f561b5">LCD_PIN_E2</a>;
<a name="l00229"></a>00229                                 }
<a name="l00230"></a>00230                                 <span class="keywordflow">else</span>
<a name="l00231"></a>00231                                 {
<a name="l00232"></a>00232                                         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>;
<a name="l00233"></a>00233                                 }
<a name="l00234"></a>00234                                 lcd_write(<a class="code" href="lcd_8h.html#fd34054a824de29fcbd441ee67faaf14">LCD_SET_DDRAM</a> + 0, 0);
<a name="l00235"></a>00235                         }
<a name="l00236"></a>00236                 }
<a name="l00237"></a>00237                 
<a name="l00238"></a>00238         lcd_waitbusy();
<a name="l00239"></a>00239 <span class="preprocessor">#endif</span>
<a name="l00240"></a>00240 <span class="preprocessor"></span>        lcd_write(c, 1);
<a name="l00241"></a>00241     }
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 
<a name="l00244"></a>00244 
<a name="l00245"></a><a class="code" href="lcd_8h.html#8ffdfcac7638368ff04364c14984266e">00245</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#8ffdfcac7638368ff04364c14984266e">lcd_puts</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s)
<a name="l00246"></a>00246 {
<a name="l00247"></a>00247   <span class="keyword">register</span> <span class="keywordtype">char</span> c;
<a name="l00248"></a>00248 
<a name="l00249"></a>00249   <span class="keywordflow">while</span> ( (c = *s++) )
<a name="l00250"></a>00250   {
<a name="l00251"></a>00251     <a class="code" href="lcd_8c.html#fa7e36b95c43d603f510273ad077cbbe">lcd_putc</a>(c);
<a name="l00252"></a>00252   }
<a name="l00253"></a>00253 }
<a name="l00254"></a>00254 
<a name="l00255"></a>00255 
<a name="l00256"></a><a class="code" href="lcd_8h.html#cb11e5a7e15154c8b4d1bb05f307483b">00256</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#cb11e5a7e15154c8b4d1bb05f307483b">lcd_puts_P</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *progmem_s)
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258     <span class="keyword">register</span> <span class="keywordtype">char</span> c;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260     <span class="keywordflow">while</span> ( (c = pgm_read_byte(progmem_s++)) ) {
<a name="l00261"></a>00261         <a class="code" href="lcd_8c.html#fa7e36b95c43d603f510273ad077cbbe">lcd_putc</a>(c);
<a name="l00262"></a>00262     }
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 
<a name="l00266"></a><a class="code" href="lcd_8h.html#f8da853dba4b9d5f2aea4e294444e14d">00266</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#f8da853dba4b9d5f2aea4e294444e14d">lcd_clrscr</a>(<span class="keywordtype">void</span>)
<a name="l00267"></a>00267 {
<a name="l00268"></a>00268         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#e0219bbb995729c477feeab487f561b5">LCD_PIN_E2</a>;
<a name="l00269"></a>00269         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#6aa8aa2057294b7d06088e834299b369">LCD_CLEAR</a>);
<a name="l00270"></a>00270         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a>=<a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>;
<a name="l00271"></a>00271         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#6aa8aa2057294b7d06088e834299b369">LCD_CLEAR</a>);
<a name="l00272"></a>00272 }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274 
<a name="l00275"></a><a class="code" href="lcd_8c.html#f28450b1acc4274a71fab57b0f7720ed">00275</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#f28450b1acc4274a71fab57b0f7720ed">init_controller</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> cmd)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277 <span class="comment">/* initial write to lcd is 8bit */</span>
<a name="l00278"></a>00278         <a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>=(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> &amp; (~(0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>))) | (0x03 &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>);
<a name="l00279"></a>00279         toggle_e();
<a name="l00280"></a>00280         <a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">delay</a>(4992);         <span class="comment">/* delay, busy flag can't be checked here */</span>
<a name="l00281"></a>00281 
<a name="l00282"></a>00282         <span class="comment">/* repeat last command */</span> 
<a name="l00283"></a>00283         toggle_e();      
<a name="l00284"></a>00284         <a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">delay</a>(64);           <span class="comment">/* delay, busy flag can't be checked here */</span>
<a name="l00285"></a>00285     
<a name="l00286"></a>00286         <span class="comment">/* repeat last command a third time */</span>
<a name="l00287"></a>00287         toggle_e();      
<a name="l00288"></a>00288         <a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">delay</a>(64);           <span class="comment">/* delay, busy flag can't be checked here */</span>
<a name="l00289"></a>00289 
<a name="l00290"></a>00290         <span class="comment">/* now configure for 4bit mode */</span>
<a name="l00291"></a>00291         <a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>=(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a> &amp; (~(0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>))) | (0x02 &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>); <span class="comment">// LCD_FUNCTION_4BIT_1LINE&gt;&gt;4</span>
<a name="l00292"></a>00292         toggle_e();
<a name="l00293"></a>00293         <a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">delay</a>(64);           <span class="comment">/* some displays need this additional delay */</span>
<a name="l00294"></a>00294         
<a name="l00295"></a>00295         <span class="comment">/* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */</span>    
<a name="l00296"></a>00296         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8c.html#b35032ab368a8bc90798e0c547fb24c2">LCD_FUNCTION_4BIT_2LINES</a>);
<a name="l00297"></a>00297         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#a2966175115943883f51e9c90478540c">LCD_DISP_OFF</a>);              <span class="comment">/* display off                  */</span>
<a name="l00298"></a>00298         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#6aa8aa2057294b7d06088e834299b369">LCD_CLEAR</a>);                 <span class="comment">/* display clear                */</span> 
<a name="l00299"></a>00299         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(<a class="code" href="lcd_8h.html#1849e2087d3034a3fffa67444beed109">LCD_MODE_DEFAULT</a>);          <span class="comment">/* set entry mode               */</span>
<a name="l00300"></a>00300         <a class="code" href="lcd_8c.html#7570f3657d5468148afe4f2e356bc41a">lcd_command</a>(cmd);                               <span class="comment">/* display/cursor control       */</span>
<a name="l00301"></a>00301 }
<a name="l00302"></a>00302 
<a name="l00303"></a><a class="code" href="lcd_8h.html#3afa3406e59f5137c3ba14e89f493cd0">00303</a> <span class="keywordtype">void</span> <a class="code" href="lcd_8c.html#3afa3406e59f5137c3ba14e89f493cd0">lcd_init</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> cmd)
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305         <span class="comment">//set IO directions</span>
<a name="l00306"></a>00306         <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#077def6ebb43bf9aee4e7cad468ed726">LCD_DATA_PORT</a>) |= 0x0F &lt;&lt; <a class="code" href="lcd_8h.html#1143c980a176ee75faa6bbb908f2ff65">LCD_DATA_OFFSET</a>;
<a name="l00307"></a>00307         <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#10f66499a3b1e8388d4f380e784d2149">LCD_CTRL_PORT</a>) |= 1&lt;&lt;<a class="code" href="lcd_8h.html#6ac777950db576df62346a5a7da5b3a7">LCD_PIN_RS</a>;
<a name="l00308"></a>00308         <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#10f66499a3b1e8388d4f380e784d2149">LCD_CTRL_PORT</a>) |= 1&lt;&lt;<a class="code" href="lcd_8h.html#74b224af2a7729172a64fbf0e5c2d400">LCD_PIN_RW</a>;
<a name="l00309"></a>00309         <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#10f66499a3b1e8388d4f380e784d2149">LCD_CTRL_PORT</a>) |= 1&lt;&lt;<a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>;
<a name="l00310"></a>00310         <a class="code" href="lcd_8c.html#ad0f4f8181754f04a3cd2221072a13bf">DDROFPORT</a>(<a class="code" href="lcd_8h.html#10f66499a3b1e8388d4f380e784d2149">LCD_CTRL_PORT</a>) |= 1&lt;&lt;<a class="code" href="lcd_8h.html#e0219bbb995729c477feeab487f561b5">LCD_PIN_E2</a>;
<a name="l00311"></a>00311           
<a name="l00312"></a>00312           
<a name="l00313"></a>00313         <span class="comment">//initialize lcd in 4 bit mode</span>
<a name="l00314"></a>00314         <a class="code" href="lcd_8c.html#deb129e484b57c960e4a118fab9cdb21">delay</a>(16000);
<a name="l00315"></a>00315         
<a name="l00316"></a>00316         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a> = <a class="code" href="lcd_8h.html#05b1bf55f9a3a1a47b2c7b581f4b2ce0">LCD_PIN_E1</a>;
<a name="l00317"></a>00317         <a class="code" href="lcd_8c.html#f28450b1acc4274a71fab57b0f7720ed">init_controller</a>(cmd);
<a name="l00318"></a>00318         <a class="code" href="lcd_8c.html#20cddb33daa86bfb43a950a416ba1b23">active_e</a> = <a class="code" href="lcd_8h.html#e0219bbb995729c477feeab487f561b5">LCD_PIN_E2</a>;
<a name="l00319"></a>00319         <a class="code" href="lcd_8c.html#f28450b1acc4274a71fab57b0f7720ed">init_controller</a>(cmd);
<a name="l00320"></a>00320 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Erzeugt am Sun Nov 16 12:25:20 2008 für nBot von&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address>
</body>
</html>
